<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<!--edge浏览器H5兼容设置-->
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<!--360浏览器H5兼容设置-->
		<meta name="renderer" content="webkit" />
		<title>电脑商城</title>
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<!--导入核心文件-->
		
		<link href="/bootstrap3/css/bootstrap.css" rel="stylesheet" type="text/css">
	
		<!-- 字体图标 -->
		<link rel="stylesheet" href="/bootstrap3/font-awesome-4.7.0/css/font-awesome.css" />
		<link rel="stylesheet" type="text/css" href="/css/top.css" />
		<link rel="stylesheet" type="text/css" href="/css/index.css" />
		<link rel="stylesheet" type="text/css" href="/css/layout.css" />
		<link rel="stylesheet" type="text/css" href="/css/reg.css" />
		<link rel="stylesheet" type="text/css" href="/css/footer.css" />
        
        <!--VUE和jquery的包-->
		<script src="/js/jquery-3.3.1.min.js"></script>
        <script src="/js/vue.js"></script>
        <script src="/js/axios-0.18.0.js"></script>
	</head>
	<body>
		<div id="app">
		<!--头部-->
        <!--头部-->
        <header class="header" style="position: absolute;">
            <img src="/images/index/stumalllogo.png" alt="" />
            <span class="pull-right" style="margin-left: 600px;margin-top: 10px;font-size: 22px;"><small>欢迎访问</small><b>电脑商城</b></span>
        </header>
		<!--主体-->
		<div class="container mycontent text-left">
			<!--透明层 -->
			<div class="regDiv">
				<p>新用户注册</p>
				<!--表单开始-->
				<form id="form-reg" class="form-horizontal" role="form">
					<!--用户名-->
					<div class="form-group">
						<label class="col-md-3 control-label">名字：</label>
						<div class="col-md-8">
							<input @blur="check()" v-model="username" type="text" class="form-control" placeholder="请输入用户名">
						</div>
					</div>
					<!--用户名已经存在-->
					<div style="display: none;" id="checkUsername">
						<span style="color: red;margin-left: 150px;">该用户名已被注册！</span>
					</div>
					<!--密码-->
					<div class="form-group">
						<label class="col-md-3 control-label"> 密码：</label>
						<div class="col-md-8">
							<input v-model="password" type="text" class="form-control" placeholder="请输入密码">
						</div>
					</div>
					<!--确认密码-->
					<div class="form-group">
						<label class="col-md-3 control-label" > 确认密码：</label>
						<div class="col-md-8">
							<input @blur="display()" v-model="password2" type="text" class="form-control" placeholder="请再次输入密码">
						</div>
					</div>
					<!--密码不一致的时候显示-->
					<div style="display: none;" id="confirm">
						<span style="color: red;margin-left: 150px;">两次输入密码不一致！</span>
					</div>
					<!--提交按钮-->
					<div class="form-group">
						<label class="col-md-3 control-label"></label>
						<div class="col-md-8">
							<input @click="reg()" id="btn-reg" class="btn btn-primary" type="button" value="立即注册" />
							<span class="pull-right"><small>已经有账号？</small><a href="login.html">登录</a></span>
						</div>
					</div>
				</form>
			</div>
		</div>
		<!--页脚开始-->
		<footer class="footer">
			<!-- 品质保障，私人定制等-->
			<div class="text-center rights container">
				<div class="col-md-offset-2 col-md-2">
					<span class="fa fa-thumbs-o-up"></span>
					<p>品质保障</p>
				</div>
				<div class="col-md-2">
					<span class="fa fa-address-card-o"></span>
					<p>私人订制</p>
				</div>
				<div class="col-md-2">
					<span class="fa fa-graduation-cap"></span>
					<p>学生特供</p>
				</div>
				<div class="col-md-2">
					<span class="fa fa-bitcoin"></span>
					<p>专属特权</p>
				</div>
			</div>
			<!--联系我们、下载客户端等-->
			<div class="container beforeBottom">
				<div class="col-md-offset-1 col-md-3">
					<div><img src="/images/index/stumalllogo.png" alt="" class="footLogo" /></div>
					<div><img src="/images/index/footerFont.png" alt="" /></div>
				</div>
				<div class="col-md-4 callus text-center">
					<div class="col-md-4">
						<ul>
							<li><a href="#"><p>买家帮助</p></a></li>
							<li><a href="#">新手指南</a></li>
							<li><a href="#">服务保障</a></li>
							<li><a href="#">常见问题</a></li>
						</ul>
					</div>
					<div class="col-md-4">
						<ul>
							<li><a href="#"><p>商家帮助</p></a></li>
							<li><a href="#">商家入驻</a></li>
							<li><a href="#">商家后台</a></li>
						</ul>
					</div>
					<div class="col-md-4">
						<ul>
							<li><a href="#"><p>关于我们</p></a></li>
							<li><a href="#">关于圆心</a></li>
							<li><a href="#">联系我们</a></li>
							<li>
								<span class="fa fa-wechat"></span>
								<span class="fa fa-weibo"></span>
							</li>
						</ul>
					</div>
				</div>
				<div class="col-md-4">
					<div class="col-md-5">
						<p>电脑商城客户端</p>
						<img src="/images/index/ios.png" class="lf">
						<img src="/images/index/android.png" alt="" class="lf" />
					</div>
					<div class="col-md-6">
						<img src="/images/index/erweima.jpg">
					</div>
				</div>
			</div>
			<!-- 页面底部-备案号 #footer -->
			<div class="col-md-12 text-center bottom">
				Copyright © 2022 dnsc.cn All Rights Reserved 京ICP备08963888号-45 <a target="_blank" href="http://www.dnsc.cn/">圆心科技集团有限公司</a> 版权所有
			</div>
		</footer>
		<!--页脚结束-->
			

		
		</div>
	</body>

</html>

<script>
	new Vue({
		el:"#app",
		data:{
			username:"",
			password:"",
			password2:"",
			checkCode:0
		},
		methods:{
			//展示密码不一致界面
			display(){
				//alert(123456);
				if (this.password != this.password2){
					//alert(123456);
					$("#confirm").prop("style","display:block;margin-top: -15px;");
					$("#confirm").fadeOut(3000);
				}
			},
			check(){
				axios.get("/user/check",{params:{username:this.username}}).then(resp => {
					this.checkCode = resp.data;
					if(resp.data == 1){
						//等于 1 代表用户已经存在了
						$("#checkUsername").prop("style","display:block;margin-top: -15px;");
						$("#checkUsername").fadeOut(3000);	
					}
				})	
			},
			//去注册
			reg(){
				if (this.password != this.password2){
					alert("两次密码输入不一致！请重新注册！");
					location.reload(true);
				}else if (this.username == null || this.password == null) {
					alert("账号或密码不能为空！请重新注册！");
					location.reload(true);
				}else if (this.checkCode == 1){
					alert("用户名已经存在！请重新注册！");
					location.reload(true);
				} 
				else {
					axios.
					get("/user/reg",{params:{username:this.username,password:this.password}}).
					then(resp => {
						if(resp.data == 1){
						//等于 1 代表注册成功了
							alert("注册成功！");
							location.href = "login.html";
						}else{
							alert("注册失败！");
						}
					})
				}
			}
		}
	})
</script>